package com.example.tass.domain;

import cn.tass.SRJ1933.devices.utis.StringUtils;
import cn.tass.exceptions.TAException;
import cn.tass.logger.Logger;

public class MyBaseRequest {
    public MyBaseRequest() {
    }

    protected void checkParamIsEmpty(String param, String paraName) throws TAException {
        if (StringUtils.isEmpty(param)) {
            Logger.appendError("The parameter %s must be set and not null.", new Object[]{paraName});
            throw new TAException("The parameter %s must be set and not null.", new Object[]{paraName});
        }
    }

    protected void checkPrivkeyType(int privKeyType, String paraName, boolean isContainEcc) throws TAException {
        int lowValue = 1;
        int hignValue = 2;
        if (isContainEcc) {
            hignValue = 3;
        }

        if (privKeyType < lowValue || privKeyType > hignValue) {
            Logger.appendError("The value of the parameter %s must be between %d and %d.", new Object[]{paraName, Integer.valueOf(lowValue), Integer.valueOf(hignValue)});
            throw new TAException("The value of the parameter %s must be between %d and %d.", new Object[]{paraName, Integer.valueOf(lowValue), Integer.valueOf(hignValue)});
        }
    }

    protected void checkEccCurveId(int privKeyType, Integer eccCurveId, String paraName) throws TAException {
        int lowValue = 1;
        int hignValue = 3;
        if (privKeyType == 3 && (null == eccCurveId || eccCurveId < lowValue || eccCurveId > hignValue)) {
            Logger.appendError("When the private key type is ECC,The value of the parameter %s must be between %d and %d.", new Object[]{paraName, Integer.valueOf(lowValue), Integer.valueOf(hignValue)});
            throw new TAException("When the private key type is ECC,The value of the parameter %s must be between %d and %d.", new Object[]{paraName, Integer.valueOf(lowValue), Integer.valueOf(hignValue)});
        }
    }
}
